<?
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
require ("s_inc.php");
$rows = 20;
$page = $_REQUEST['page']?$_REQUEST['page']:1;
//權限
admin_main::pageChk('cats_set');
?>
<?php require("s_head.tpl.php"); ?>
<?
$db_help = &new db($scfg['db']['help']);
$table 	  = 'my_affiche';
if($_POST || $_GET['act'] == 'del')
{
	$act = $_REQUEST['act'];
	//print_r($_POST);
	if($act == 'modify')
	{
		$id = (int)$_REQUEST['id'];
		$subject = $_POST['subject'];
		$author = $_POST['author'];
		$contents = $_POST['contents'];
		$rs = $db_help->update($table
								,array("subject"=>$subject,"author"=>$author,"contents"=>$contents)
								," id =? "
								,$id);
		if($rs)
		{
		 	echo g::msg("成功：更新公告成功!");
			
		}else
		{
		    echo g::msg("提示：没有更新！可能是你没有新的改动，如改动请稍重试！");
		}
	}elseif($act == 'add')
	{
		$subject = $_POST['subject'];
		$author = $_POST['author'];
		$contents = $_POST['contents'];
		$id = $db_help->insert($table,array("subject"=>$subject,"author"=>$author,"contents"=>$contents,"save_time"=>time()));
		if($id)
		{
		 	echo g::msg("成功：公告添加有成功!"); 
		 	g::gowin("?");
			exit();
		}else
		{
		    echo g::msg("提示：系統忙请稍后重试!");
		}
	}elseif($act == 'del')
	{
		$id = (int)$_REQUEST['id'];
		if($id)
		{
		 	$rs = $db_help->delete($table," id =? ",$id);
			//echo  $db_help->getsql();
			//exit();
		 	if($rs)
		 	{
		 	    echo g::msg("成功：删除公告成功！");
		 	}else
		 	{
		 	 	echo g::msg("失败：公告不存在，或系统忙请稍后再试!");   
		 	}    
		}else
		{
		    echo g::msg("提示：参数有误，请误非法操作!");
		}
		g::gowin();
	}
}
//////////////////////////////////////////////////////////////////////////////////
$act = $_GET['act'];
if($act == 'list' || empty($act))
{
    $where      = array();
    $pg			= pg::sp($db_help,$table,$where,$page,$rows);
	$rs 		= $db_help->dataArray("select id,chk_yn,cats,author,subject,save_time from {$table} {$where['where']} order by id desc limit {$pg['begin']},".$rows,$where['bind']);
?>
<table width="100%"  border="0" cellpadding="4" cellspacing="1" class="tableoutline">
	<tr>
	<td colspan="4" class="tbhead"><?=SITE_NIKENAME?>公告管理</td>
  </tr>
  <tr class="_data_" style="font-weight:bold;">
	<td width="55%">標題</td>
	<td width="17%">作者</td>
    <td width="15%">时间</td>
    <td width="13%">操作</td>
  </tr>
  <?
   foreach($rs as &$v)
   {   		
  ?>
  <tr class="_data_">
    <td align="left"><?=$v['subject']?></td>
    <td align="left"><?=$v['author']?></td>
    <td align="left"><?=g::time($v['save_time'],1)?></td>
    <td align="left">[<a href="?act=modify&id=<?=$v['id']?>">修改</a>] [<a href="?act=del&id=<?=$v['id']?>" onClick="return oAdmin.msgYn();">刪除</a>]</td>
  </tr>
  
  <?
   }
  ?><tr>
    <td colspan="4" align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><?=$pg['str']?></td>
        <td align="right"><ul class="page">
				<?=implode("",$pg['np'])?>
			</ul></td>
      </tr>
    </table></td>
    </tr>
</table>
<?
}elseif($act == 'add')
{
?>

<form method="post" onSubmit="return XypForm(this)">
<table width="100%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
        <tr>
        <td colspan="2" class="tbhead">添加公告</td>
      </tr>
	  <tr class="_data_">
		<td align="right">标题：</td>
		<td align="left"> 
		 <input name="subject" require="1" value="<?=$_POST['subject']?>" type="text" id="subject" size="30" maxlength="32"></td>
	  </tr>
	  <tr class="_data_">
        <td width="14%" align="right">作者：        </td>
        <td width="86%" align="left"><input name="author"  require="1" type="text" id="author" size="20" maxlength="30" value="<?=admin_main::getMaster()?>"></td>
      </tr>
      <tr class="_data_">
        <td align="right" valign="top">内容：</td>
        <td align="left"><textarea name="contents" cols="50" rows="3" id="contents" style="display:none"><?=$_POST['contents']?></textarea>
        <iframe ID="Editor" name="Editor" src="<?=surl::get("www");?>editors/edit.htm?id=contents" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" style="height:320px;width:100%"></iframe></td>
      </tr>
      <tr class="_data_">
        <td>&nbsp;</td>
        <td><input type="submit" class="bginput">
        <input type="reset" class="bginput">
        
        <input name="act" type="hidden" id="act" value="add"></td>
      </tr>
</table>
</form>
<?
}elseif($act == 'modify')
{
	$id = (int)$_REQUEST['id'];
	$rs = $db_help->row("select * from {$table} where id=? ",$id);
?>
<form method="post" onSubmit="return XypForm(this)">
<table width="100%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
        <tr>
        <td colspan="2" class="tbhead">更新公告</td>
    </tr>
	 <tr class="_data_">
		<td align="right">标题：</td>
		<td align="left"> 
		 <input name="subject" require="1" value="<?=$rs['subject']?>" type="text" id="subject" size="30" maxlength="32"></td>
	  </tr>
	  <tr class="_data_">
        <td width="14%" align="right">作者：        </td>
        <td width="86%" align="left"><input name="author"  require="1" type="text" id="author" size="20" maxlength="30" value="<?=$rs['author']?>"></td>
      </tr>
      <tr class="_data_">
        <td align="right" valign="top">内容：</td>
        <td align="left"><textarea name="contents" cols="50" rows="3" id="contents" style="display:none"><?=$rs['contents']?></textarea>
        <iframe ID="Editor" name="Editor" src="<?=surl::get("www");?>editors/edit.htm?id=contents" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" style="height:320px;width:100%"></iframe></td>
      </tr>
      <tr class="_data_">
        <td>&nbsp;</td>
        <td><input type="submit" class="bginput">
        <input type="reset" class="bginput">
        <input name="id" type="hidden" id="id" value="<?=$rs['id']?>">
        <input name="act" type="hidden" id="act" value="modify"></td>
      </tr>
</table>
</form>
<? }?>
<? include("s_copyRight.tpl.php"); ?>